<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="com.cr.model.Customer"%>
<%@ page import="com.cr.model.MyOrder"%>
<%@ page import="com.cr.model.Cloth"%>
<%@ page import="com.cr.model.OrderDetail"%>
<%@ page import="com.cr.service.ClothService"%>
<%@ page import="com.cr.service.MyOrderService"%>
<%@ page import="com.cr.service.OrderDetailService"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>Order detail</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<link rel="stylesheet" type="text/css" href="easyui/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="easyui/themes/icon.css">
	<link rel="stylesheet" type="text/css" href="style/style.css">
	<script type="text/javascript" src="easyui/jquery-1.7.2.min.js"></script>
	<script type="text/javascript" src="easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="script/main.js"></script>
  </head>
  
  <body>
   	<jsp:include page="header.jsp"></jsp:include>
    <div id="content">
    	<div id="search">
    		<p><input id="searcher" type="text"/></p>
    	</div>
    		<%
    			Customer customer=null;
    		 	if(session.getAttribute("customer")!=null)
    		 	{
    		 		customer=(Customer)session.getAttribute("customer");
    		 	}
    		 	if(customer==null)
    		 	{
    		 		out.print("<script>location.href='login.jsp';</script>");
    		 	}
    		 	
    		 	String id=request.getParameter("id");
    		 	
    		 	MyOrderService orderService=new MyOrderService();
    		 	MyOrder order=null;
    		 	
    		 	if(id!=null)
    		 	{
    		 		order = orderService.getMyOrder(Long.parseLong(id));
    		 	}
    		 	
    		 	if(order!=null)
    		 	{
    		 		OrderDetailService detailService=new OrderDetailService();
    		 		
    		 		List<OrderDetail> details=detailService.getOrderDetails(Long.parseLong(id));
    		 %>
    	<div id="order" style="text-align:left;padding-left:30px;float:left;width:45%;">
    		 	<div class="title">client information</div>
    		 	<table border="1">
	    			<tr>
	    				<td width=150>Client Name：</td>
	    				<td width=200><%=order.getRecvName() %></td>
	    			</tr>
	    			<tr>
	    				<td>Province：</td>
	    				<td><%=order.getRecvProvince() %></td>
	    			</tr>
	    			<tr>
	    				<td>Address：</td>
	    				<td><%=order.getRecvAddr() %></td>
	    			</tr>
	    			<tr>
	    				<td>Mobile Phone：</td>
	    				<td><%=order.getRecvPhone() %></td>
	    			</tr>
	    			<tr>
	    				<td>E-mail：</td>
	    				<td><%=order.getRecvEmail() %></td>
	    			</tr>
	    			<tr>
	    				<td>Postal Code：</td>
	    				<td><%=order.getPostCode()==null?"&nbsp;":order.getPostCode() %></td>
	    			</tr>
	    		</table>
	    		<div class="title">payment way and send way</div>
	    		<table border="1">
	    			<tr>
	    				<td width=150>Payment Way：</td>
	    				<td width=200><%=order.getPayMethod() %></td>
	    			</tr>
	    			<tr>
	    				<td>Send Way：</td>
	    				<td><%=order.getPostMethod() %></td>
	    			</tr>
	    			<tr>
	    				<td>Cost：</td>
	    				<td>Free</td>
	    			</tr>
	    		</table>
	    		<div class="title">rent message</div>
	    		<table border="1">
	    			<tr>
	    				<td width=150>Rent days：</td>
	    				<td width=200><%=order.getRentDays() %>Day</td>
	    			</tr>
	    		</table>
    	</div>
    	<div id="detail" style="float:right;width:48%;padding-left:10px;text-align:left;">
    		<div class="title">Order Clothes</div>
    		<table border='1' style='border-collapse: collapse;width:98%;font-size:10pt;' bordercolor='#CCCCCC'>
    		 	<tr class="t_head">
    		 		<td>No.</td>
    		 		<td>Cloth</td>
    		 		<td>Quantity</td>
    		 		<td>SubTotal</td>
    			</tr>
    		
    		<%
    			int count=0;
    			float subTotal=0;
    			for(OrderDetail detail:details)
    			{
    				count++;
    				ClothService clothService=new ClothService();
    				
    				Cloth cloth=clothService.getCloth(detail.getClothId());
    				subTotal+=cloth.getPrice()*detail.getQuantity();
    		 %>
    		 		<tr>
    		 			<td><%=count %></td>
    		 			<td><img src="<%=cloth.getPicture().get(0) %>" class="cart_img" /> <%=cloth.getName() %></td>
    		 			<td><%=detail.getQuantity() %></td>
    		 			<td><%=subTotal %></td>
    		 		</tr>
    		 <%
    		 	}
    		  %>
    		  </table>
    		  <div class="float_right" style="padding-right:20px;">
    		  		Total:<%=order.getRentDays() %>(Day) x <%=subTotal %>(RMB/Day) = <%=order.getTotal() %>(RMB)
    		  </div>
    	</div>
    	 <%
    		 }
    		 else
    		 {
    		 	out.print("some error happend");
    		 }
    		%>
    </div>
    <jsp:include page="footer.jsp"></jsp:include>
  </body>
</html>
